package com.ayf.payment.game.api.utils;

import java.util.Random;

/**
 * @author admin
 * @Title: EncryptedRandomKey
 * @Copyright: Copyright (c) 2018
 * @Description: <br>
 * @Company: 123.com
 * @Created on 2019/3/6下午9:42
 */
public class EncryptedRandomKey {

    private static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";


    /**
     * 返回一个定长的随机字符串(只包含大小写字母、数字)
     *
     * @param length
     *            随机字符串长度
     * @return 随机字符串
     */
    private static String generateString(int length) {
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length())));
        }
        return sb.toString();
    }

    public static String getEncryptedRandomKey() {
        return generateString(16);
    }

    public static void main(String[] args) {
        System.out.println(EncryptedRandomKey.getEncryptedRandomKey());
    }
}
